using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.Design.MatchingRules;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;

namespace EntLibContrib.PolicyInjection.Design
{
    public class OrMatchingRuleNode : MatchingRuleNode, ICompositeMatchingRuleNode
    {
        private OrMatchingRuleData ruleData;

        public OrMatchingRuleNode()
            :this(new OrMatchingRuleData(Resources.OrMatchingRuleName))
        {
        }

        public OrMatchingRuleNode(OrMatchingRuleData ruleData)
            :base(ruleData)
        {
            this.ruleData = ruleData;
        }

        
        public override MatchingRuleData GetConfigurationData()
        {
            OrMatchingRuleData ruleData = new OrMatchingRuleData(this.Name);
            foreach (MatchingRuleNode node in this.Nodes)
            {
                ruleData.MatchingRules.Add(node.GetConfigurationData());
            }
            return ruleData;
        }

        #region ICompositeMatchingRuleNode Members

        [Browsable(false)]
        public IEnumerable<MatchingRuleData> ChildRules
        {
            get { return ruleData.MatchingRules; }
        }

        #endregion
    }
}
